package ui;

import javazoom.jl.player.Player;

import javax.swing.*;
import java.awt.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;

public class Main {

    public static void main(String[] args) {
        // 播放音乐（仅在启动时）
        new Thread(() -> playMusic("D:\\浏览器下载\\M500004WNEZC2TffDj.mp3")).start();
        showMainMenu(); // 显示主界面
    }

    public static void showMainMenu() {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("请选择登录身份");
            frame.setSize(350, 250);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().setBackground(new Color(255, 240, 245));

            frame.setLayout(new BorderLayout());

            JLabel label = new JLabel("请选择您的身份", SwingConstants.CENTER);
            label.setFont(new Font("微软雅黑", Font.BOLD, 22));
            label.setForeground(new Color(255, 105, 180));
            frame.add(label, BorderLayout.NORTH);

            JPanel buttonPanel = new JPanel();
            buttonPanel.setBackground(new Color(255, 240, 245));
            buttonPanel.setLayout(new GridLayout(2, 1, 20, 20));
            buttonPanel.setBorder(BorderFactory.createEmptyBorder(30, 60, 30, 60));

            JButton studentButton = createPinkButton("学生登录");
            studentButton.addActionListener(e -> {
                frame.dispose();
                new LoginFrame(); // 进入学生登录
            });

            JButton teacherButton = createPinkButton("教师登录");
            teacherButton.addActionListener(e -> {
                frame.dispose();
                new TeacherLoginFrame(); // 进入教师登录
            });

            buttonPanel.add(studentButton);
            buttonPanel.add(teacherButton);

            frame.add(buttonPanel, BorderLayout.CENTER);
            frame.setVisible(true);
        });
    }

    private static void playMusic(String filePath) {
        try (FileInputStream fis = new FileInputStream(filePath);
             BufferedInputStream bis = new BufferedInputStream(fis)) {
            Player player = new Player(bis);
            player.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static JButton createPinkButton(String text) {
        JButton button = new JButton(text);
        button.setFont(new Font("微软雅黑", Font.PLAIN, 18));
        button.setBackground(new Color(255, 182, 193));
        button.setForeground(Color.WHITE);
        button.setFocusPainted(false);
        button.setBorder(BorderFactory.createLineBorder(new Color(255, 105, 180), 1));
        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
        button.setOpaque(true);
        return button;
    }
}
